//
//  IdentityStepController.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/30.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "IdentityStepController.h"
#import "SetNewPasswordController.h"

@interface IdentityStepController ()
@property (weak, nonatomic) IBOutlet UIProgressView *progress;
@property (weak, nonatomic) IBOutlet UITextField *codeText;
@property (weak, nonatomic) IBOutlet UIButton *nextBtn;
@property (weak, nonatomic) IBOutlet UILabel *typeLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UIButton *getCodeBtn;

@end

@implementation IdentityStepController

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)setNavi
{
    self.title = @"修改支付密码";
}

-(void)setUI
{
    self.view.backgroundColor =  Color(245, 245, 245);
    [self.progress setProgress:0.75 animated:YES];
    [self.codeText addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    self.typeLabel.text = self.labelText;
    self.phoneLabel.text = self.starPhoneNumber;
}

- (void)textFieldDidChange:(UITextField *)textField
{
    if (self.codeText.text.length == 6) {
        self.nextBtn.userInteractionEnabled = YES;
        [self.nextBtn setBackgroundColor:MainColor];
    }else
    {
        [self.nextBtn setBackgroundColor:MainBtnColor];
        self.nextBtn.userInteractionEnabled = NO;
    }
}

// 开启倒计时效果
-(void)openCountdown{
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"token":self.userToken};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@deposit-account/send-change-payment-password-sms",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            [self.getCodeBtn startWithTime:59 title:@"获取验证码" countDownTitle:@"重新发送" mainColor:[UIColor clearColor] countColor:[UIColor clearColor]];
                }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}

- (IBAction)getCodeAction:(id)sender {
    [self openCountdown];
}


- (IBAction)nextAction:(id)sender {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary * dict = @{@"token":self.userToken,@"sms_code":self.codeText.text};
    [HTTPTool POSTForm:[NSString stringWithFormat:@"%@deposit-account/send-change-payment-password-sms",BaseUrl] para:dict success:^(BOOL isSuccess, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        if (isSuccess) {
            SetNewPasswordController * vc = [[SetNewPasswordController alloc]init];
            vc.labelText = self.labelText;
            [self.navigationController pushViewController:vc animated:YES];
        }
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
